﻿namespace Huayou.UI.WebControls
{
    using System;
    using System.Xml;

    public class MenuGroup
    {
        internal string ClientSideID;
        protected XmlElement GroupNode;
        internal int MaxLeftIconWidth = 0;
        internal int MaxRightIconWidth = 0;
        protected WebMenu Menu;

        public MenuGroup(XmlElement node, WebMenu menu)
        {
            this.GroupNode = node;
            this.Menu = menu;
            if (node.Attributes["ClientSideID"] != null)
            {
                this.ClientSideID = node.Attributes["ClientSideID"].Value;
            }
            int num = 0;
            int num2 = 0;
            for (int i = 0; i < node.ChildNodes.Count; i++)
            {
                if ((node.ChildNodes[i].Attributes["LeftIconWidth"] != null) && (int.Parse(node.ChildNodes[i].Attributes["LeftIconWidth"].Value) > num))
                {
                    num = int.Parse(node.ChildNodes[i].Attributes["LeftIconWidth"].Value);
                }
                if ((node.ChildNodes[i].Attributes["RightIconWidth"] != null) && (int.Parse(node.ChildNodes[i].Attributes["RightIconWidth"].Value) > num2))
                {
                    num2 = int.Parse(node.ChildNodes[i].Attributes["RightIconWidth"].Value);
                }
            }
            this.MaxLeftIconWidth = num;
            this.MaxRightIconWidth = num2;
        }

        protected bool IsTopGroup()
        {
            return (this.GroupNode.ParentNode.Name == "MenuData");
        }

        public string CssClass
        {
            get
            {
                if (this.GroupNode.Attributes["CssClass"] != null)
                {
                    return this.GroupNode.Attributes["CssClass"].Value;
                }
                if (this.Menu.DefaultGroupCssClass != null)
                {
                    return this.Menu.DefaultGroupCssClass;
                }
                return null;
            }
            set
            {
                this.GroupNode.SetAttribute("CssClass", value);
            }
        }

        public string ExpandDirection
        {
            get
            {
                if (this.GroupNode.Attributes["ExpandDirection"] != null)
                {
                    return this.GroupNode.Attributes["ExpandDirection"].Value.ToLower();
                }
                return null;
            }
            set
            {
                this.GroupNode.SetAttribute("ExpandDirection", value);
            }
        }

        public string ExpandEffect
        {
            get
            {
                if (this.GroupNode.Attributes["ExpandEffect"] != null)
                {
                    return this.GroupNode.Attributes["ExpandEffect"].Value.ToLower();
                }
                return "none";
            }
            set
            {
                this.GroupNode.SetAttribute("ExpandEffect", value);
            }
        }

        public int ExpandOffsetX
        {
            get
            {
                if (this.GroupNode.Attributes["ExpandOffsetX"] != null)
                {
                    return int.Parse(this.GroupNode.Attributes["ExpandOffsetX"].Value);
                }
                return 0;
            }
            set
            {
                this.GroupNode.SetAttribute("ExpandOffsetX", value.ToString());
            }
        }

        public int ExpandOffsetY
        {
            get
            {
                if (this.GroupNode.Attributes["ExpandOffsetY"] != null)
                {
                    return int.Parse(this.GroupNode.Attributes["ExpandOffsetY"].Value);
                }
                return 0;
            }
            set
            {
                this.GroupNode.SetAttribute("ExpandOffsetY", value.ToString());
            }
        }

        public string Height
        {
            get
            {
                if (this.GroupNode.Attributes["Height"] != null)
                {
                    return this.GroupNode.Attributes["Height"].Value;
                }
                if (!(!this.IsTopGroup() || this.Menu.Height.IsEmpty))
                {
                    return this.Menu.Height.ToString();
                }
                return null;
            }
            set
            {
                this.GroupNode.SetAttribute("Height", value.ToString());
            }
        }

        public string ID
        {
            get
            {
                if (this.GroupNode.Attributes["ID"] != null)
                {
                    return this.GroupNode.Attributes["ID"].Value;
                }
                return null;
            }
            set
            {
                this.GroupNode.SetAttribute("ID", value);
            }
        }

        public MenuItems Items
        {
            get
            {
                return new MenuItems(this.GroupNode, this.Menu);
            }
        }

        public int ItemSpacing
        {
            get
            {
                if (this.GroupNode.Attributes["ItemSpacing"] != null)
                {
                    return int.Parse(this.GroupNode.Attributes["ItemSpacing"].Value);
                }
                return this.Menu.DefaultItemSpacing;
            }
            set
            {
                this.GroupNode.SetAttribute("ItemSpacing", value.ToString());
            }
        }

        public string Orientation
        {
            get
            {
                if (this.GroupNode.Attributes["Orientation"] != null)
                {
                    return this.GroupNode.Attributes["Orientation"].Value.ToLower();
                }
                return "vertical";
            }
            set
            {
                this.GroupNode.SetAttribute("Orientation", value);
            }
        }

        public string Width
        {
            get
            {
                if (this.GroupNode.Attributes["Width"] != null)
                {
                    return this.GroupNode.Attributes["Width"].Value;
                }
                if (!(!this.IsTopGroup() || this.Menu.Width.IsEmpty))
                {
                    return this.Menu.Width.ToString();
                }
                return null;
            }
            set
            {
                this.GroupNode.SetAttribute("Width", value.ToString());
            }
        }
    }
}

